﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
/// <summary>
/// Summary description for ReservationService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class ReservationService : System.Web.Services.WebService {

    public ReservationService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    private Database db = DatabaseFactory.CreateDatabase("cns");
    [WebMethod]

    public DataTable getcountry()
    {
        DataTable table = new DataTable();
        table.TableName = "countries";
        var country = db.ExecuteDataSet(CommandType.StoredProcedure, "sp_countries");
        if (country.Tables.Count >= 0)
            table = country.Tables[0];
        return table;

    }
    [WebMethod]
    public DataTable getPaymentType()
    {
        DataTable table = new DataTable();
        table.TableName = "paymenttype";
        var paymenttype = db.ExecuteDataSet(CommandType.StoredProcedure, "sp_GetPaymentType");
        if (paymenttype.Tables.Count >= 0)
            table = paymenttype.Tables[0];
        return table;
    }
    [WebMethod]
    public DataTable getReserveType()
    {
        DataTable table = new DataTable();
        table.TableName = "reservation";

        var reservation = db.ExecuteDataSet(CommandType.StoredProcedure, "sp_getReserveType");
        if (reservation.Tables.Count >= 0)

            table = reservation.Tables[0];

        return table;
    }
    [WebMethod]
    public DataTable getRoomType()
    {
        DataTable table = new DataTable();
        table.TableName = "roomtype";

        var roomtype = db.ExecuteDataSet(CommandType.StoredProcedure, "sp_getRoomType");
        if (roomtype.Tables.Count >= 0)

            table = roomtype.Tables[0];

        return table;

    }
    [WebMethod]
    public DataTable getIdentification()
    {
        DataTable table = new DataTable();
        table.TableName = "Identification";

        var Identification = db.ExecuteDataSet(CommandType.StoredProcedure, "sp_identification");
        if (Identification.Tables.Count >= 0)

            table = Identification.Tables[0];

        return table;

    }
    [WebMethod]
    public DataTable getcardtype()
    {
        DataTable table = new DataTable();
        table.TableName = "cardtype";

        var cardtype = db.ExecuteDataSet(CommandType.StoredProcedure, "sp_getcardtype");
        if (cardtype.Tables.Count >= 0)

            table = cardtype.Tables[0];

        return table;

    }
    [WebMethod]
    public DataTable getcompany()
    {
        DataTable table = new DataTable();
        table.TableName = "company";
        var company = db.ExecuteDataSet(CommandType.StoredProcedure, "sp_getcompany");
        if (company.Tables.Count >= 0)

            table = company.Tables[0];
        return table;
    }
    [WebMethod]
    public DataTable getroom2()
    {
        DataTable table = new DataTable();
        table.TableName = "description";
        var description = db.ExecuteDataSet(CommandType.StoredProcedure, "sp_getroom2");
        if (description.Tables.Count >= 0)
        {
            table = description.Tables[0];
        }
        return table;
    }
    [WebMethod]
    public DataTable getreportmonth(int month, int year)
    {
        DataTable table = new DataTable();
        table.TableName = "reportmonth";
        var reportmonth = db.ExecuteDataSet("report_reservation", month, year);
        if (reportmonth.Tables.Count >= 0)
        {
            table = reportmonth.Tables[0];
        }
        return table;
    }
    [WebMethod]
    public DataTable getreportday(int day, int month, int year)
    {
        DataTable table = new DataTable();
        table.TableName = "reportday";
        var reportday = db.ExecuteDataSet("report_reservation_day", day, month, year);
        if (reportday.Tables.Count >= 0)
        {
            table = reportday.Tables[0];
        }
        return table;
    }
    [WebMethod]
    public DataTable reportconfirm(string tenkh)
    {
        DataTable table = new DataTable();
        table.TableName = "reportconfirm";
        var reportconfirm = db.ExecuteDataSet("sp_reservereport", tenkh);
        if (reportconfirm.Tables.Count >= 0)
        {
            table = reportconfirm.Tables[0];
        }
        return table;


        //DataTable table = new DataTable();
        //table.TableName = "formcaption";
        //var formcaption = db.ExecuteDataSet("sp_GetFormCapion", formname);
        //if (formcaption.Tables.Count >= 0)
        //    table = formcaption.Tables[0];
        //return table;
    }
    [WebMethod]
    #region Method
    public int InsertReservation(string FirstName, string LastName, bool Gender, DateTime Birthday, string IDType, string IDNo, string GuestAddress, string City, string country,
                            string Email, string Phone, string Mobile, string CompanyID, string ReserveTypeID, string GuestTypeID,
                            string PaymentTypeID, int CardTypeID, string CardNo, DateTime CheckIn, DateTime CheckOut, string RoomTypeID, string RoomNumber, int Rooms, string RoomperType, int Adult, int Child,
                            string status, int Cashier)
    {
        int result = db.ExecuteNonQuery("sp_InsertReservation", FirstName, LastName, Gender, Birthday, IDType, IDNo, GuestAddress, City, country,
                            Email, Phone, Mobile, CompanyID, ReserveTypeID, GuestTypeID,
                            PaymentTypeID, CardTypeID, CardNo, CheckIn, CheckOut, RoomTypeID, RoomNumber, Rooms, RoomperType, Adult, Child,
                            status, Cashier);
        return result;
    }
    [WebMethod]
    public int AddReservation(
                            string FirstName,
                            string LastName,
                            bool Gender,
                            string Phone,
                            string Mobile,
                            string ReserveTypeID,
                            string GuestTypeID,
                            string PaymentTypeID,
                            int CardTypeID,
                            string CardNo,
                            DateTime CheckIn,
                            DateTime CheckOut,
                            string RoomTypeID,
                            Int16 Rooms,
                            int Adult,
                            int Child,
                            string IDType,
                            string IDNo,
                            string Email)
    {
        int result = db.ExecuteNonQuery("sp_AddReservation",
                                                                        FirstName,
                                                                        LastName,
                                                                        Gender,
                                                                        Phone,
                                                                        Mobile,
                                                                        ReserveTypeID,
                                                                        GuestTypeID,
                                                                        PaymentTypeID,
                                                                        CardTypeID,
                                                                        CardNo,
                                                                        CheckIn,
                                                                        CheckOut,
                                                                        RoomTypeID,
                                                                        Rooms,
                                                                        Adult,
                                                                        Child,
                                                                        IDType,
                                                                        IDNo,
                                                                        Email
                                                                        );
        return result;
    }
    [WebMethod]
    public DataTable Search(int ReservationNo)
    {
        DataTable table = new DataTable();
        table.TableName = "Reservation";
        var userinfo = db.ExecuteDataSet("sp_SearchReservation", ReservationNo);
        if (userinfo.Tables.Count >= 0)
            table = userinfo.Tables[0];
        return table;
    }
    #endregion
    [WebMethod]
    #region method
    public int InsertReservationcompany(string FirstName, string LastName, bool Gender, DateTime Birthday, string IDType, string IDNo, string GuestAddress, string City, string country,
                            string Email, string Phone, string Mobile, string CompanyID, string ReserveTypeID, string GuestTypeID,
                            string PaymentTypeID, int CardTypeID, string CardNo, DateTime CheckIn, DateTime CheckOut, string RoomTypeID, string RoomNumber, int Rooms, string RoomperType, int Adult, int Child,
                            string status, int Cashier, string CompanyName, string addresscompany, string dienthoaiban, string didong, string fax)
    {
        int result = db.ExecuteNonQuery("sp_InsertReservationcompany", FirstName, LastName, Gender, Birthday, IDType, IDNo, GuestAddress, City, country,
                            Email, Phone, Mobile, CompanyID, ReserveTypeID, GuestTypeID,
                            PaymentTypeID, CardTypeID, CardNo, CheckIn, CheckOut, RoomTypeID, RoomNumber, Rooms, RoomperType, Adult, Child,
                            status, Cashier, CompanyName, addresscompany, dienthoaiban, didong, fax);
        return result;
    }
    #endregion
}
